<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateUserRolesTable extends Migrator
{
    public function change()
    {
        $table = $this->table('user_roles', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_unicode_ci']);
        $table->addColumn('user_id', 'integer', ['null' => false, 'comment' => '用户ID'])
              ->addColumn('role_id', 'integer', ['null' => false, 'comment' => '角色ID'])
              ->addColumn('created_at', 'timestamp', ['null' => true])
              ->addColumn('updated_at', 'timestamp', ['null' => true])
              ->addIndex(['user_id', 'role_id'], ['unique' => true])
              ->create();
    }
} 